package com.hsd.survey.action;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsd.survey.service.ISurveyMobileService;

/**
 * <p>
 * 类描述：移动端问卷服务类
 * <p>
 * 创建人：Abdi
 * <p>
 * 创建时间：2013-10-25 下午08:37:37
 */
@Controller
@RequestMapping("/mobile")
public class SurveyMobileAction {
	@Autowired
	private ISurveyMobileService mobileService;
	
	/**
	 * 移动端查看服务器问卷情况
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/checkSurveysOut.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String checkSurveysOut(HttpServletRequest request,ModelMap model){
		String surveyuuids = request.getParameter("surveyuuids");
		
		JSONObject surveyListData = mobileService.checkSurveyOut(surveyuuids);
		return surveyListData.toString();
	}
	
	/**
	 * 移动端下载指定问卷
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/loadSurveyData.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String loadSurveyData(HttpServletRequest request,ModelMap model){
		String surveyuuid = request.getParameter("surveyuuid");
		JSONObject surveyData = mobileService.loadOneSurveyData(surveyuuid);
		return surveyData.toString();
	}
	
	/**
	 * 移动端上传问卷答案
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/uploadResultData.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String uploadResultData(HttpServletRequest request,ModelMap model){
		String research = request.getParameter("research");
		String resultlist = request.getParameter("resultlist");
		System.out.println("==========>>>> 接收到答题 ： " + research);
		System.out.println("==========>>>> 接收到问卷数据 ： " + resultlist);
		
		JSONObject responseData = mobileService.uploadResultData(research, resultlist);
		return responseData.toString();
	}
	/**
	 * 移动端用户登录验证
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/mobileLogin.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String mobileLogin(HttpServletRequest request,ModelMap model){
		String username = request.getParameter("username"); 
		String password = request.getParameter("password"); 
		String deviceid = request.getParameter("deviceid");  
		JSONObject loginData = mobileService.mobileLogin(username,password,deviceid);
		return loginData.toString();
	}
	/**
	 * 移动端下载用户信息
	 * @param request
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/loadUserData.do",produces = {"application/json;charset=UTF-8"})
	public @ResponseBody String loadUserData(HttpServletRequest request,ModelMap model){
		String loginid = request.getParameter("loginid"); 
		JSONObject surveyData = mobileService.loadUserData(loginid);
		return surveyData.toString();
	}
}
